#ifndef MYSERVER_H
#define MYSERVER_H

#include <QTcpServer>
#include <QThreadPool>
#include <QTimer>
#include "myclient.h"
#include "mytask.h"
#include "mythread.h"
#include <QMap>
#include <QQueue>
#include <QMutex>
#include "MsgDef.h"
static QMutex mutexlock;
class MyServer : public QTcpServer
{
    Q_OBJECT
public:
    explicit MyServer(QObject *parent = 0);
    ~MyServer();
    bool StartServer(quint16 port);
protected:
    void incomingConnection(int handle);
signals:
    void stop();
    void start();
public slots:
    //void slot_DisplayMsg(QString msg);
    void slot_SendMsg(int socket, QString msg);
    //void slot_InsetNewIpAndRow(const QString &ip,int rowNum);
    //bool CheckexistIp(const QString &ip,int &rowNum);
    void StopServer();
    void slot_ThreadCount();
private:
    QThreadPool *pool;
    int m_handle;
    QMap<int,MyTask*> m_socDes2TaskMap;
    QMap<QString,MyTask*> m_Ip2TaskMap;
    QMap<QString,int> m_Ip2RowNumMap;
    MyTask* m_currentTask;
    QQueue<QString> m_qClientIp;
    QMutex mutex;
    bool m_bIsStart;
};
MyServer* getServer();
#endif // MYSERVER_H
